package helper.scxml.scxml2.t5_traffic_train.math

import helper.base.list.ArrayListHelper.ArrayListExpand.mathMinus
import helper.base.list.ArrayListHelper.ArrayListExpand.toCovarianceMatrix
import helper.scxml.scxml2.DistanceHelper.getEuclideanDistance
import helper.scxml.scxml2.MathHelper.DSSUnit
import helper.scxml.scxml2.MathHelper.DSSUnit.Expand.toDSSUnit
import org.junit.Test
import kotlin.math.pow

internal class Test {
    @Test
    fun t_cal_3e() {
        val d = 3.0 * Math.E.pow(-(2.0).pow(0.5))
        val rs = d.toString()
        println(rs)
        //0.7293502033026426
    }

    @Test
    fun t_cal_2e() {
        val d = 2.0 * Math.E.pow(-(2.0).pow(0.5))
        val rs = d.toString()
        println(rs)
        //0.4862334688684284
    }

    @Test
    fun t1() {
        val v1 = arrayListOf(11.0, 1.0)
        val v2 = arrayListOf(12.0, 2.0)
        val v3 = arrayListOf(13.0, 3.0)
        val vs: DSSUnit = arrayListOf(v1, v2, v3).toDSSUnit()
        val mean = vs.mean
        println(mean)
        vs.dss.forEach {
            val minus = it.mathMinus(mean)
            println(minus)
        }
        vs.dss.forEach {
            val weightOf = vs.getWeightOf(
                it,
                DSSUnit::getDistanceToMean,
            )
            println(weightOf)
        }
        //[12.0, 2.0]
        //[-1.0, -1.0]
        //[0.0, 0.0]
        //[1.0, 1.0]
        //0.4862334688684284
        //2.0
        //0.4862334688684284
    }

    @Test
    fun t2() {
        val v1 = arrayListOf(3.0, 4.0)
        val v2 = arrayListOf(6.0, 8.0)
        val euclideanDistance = getEuclideanDistance(v1, v2)
        val rs = euclideanDistance.toString()
        println(euclideanDistance)
        assert(
            rs == """
            5.0
        """.trimIndent()
        )
    }

    @Test
    fun t3() {
        val v1 = arrayListOf(1.0, 2.0, 3.0)
        val v2 = arrayListOf(4.0, 5.0, 6.0)
        val euclideanDistance = getEuclideanDistance(v1, v2)
        val rs = euclideanDistance.toString()
        println(euclideanDistance)
        assert(
            rs == """
            5.196152422706632
        """.trimIndent()
        )
    }

    @Test
    fun testMean() {
        val list = arrayListOf(
            arrayListOf(1.0, 2.0, 3.0),
            arrayListOf(4.0, 5.0, 6.0),
            arrayListOf(7.0, 8.0, 9.0),
        ).toDSSUnit()
        println(list.mean)
    }

    @Test
    fun test_getCovarianceMatrix() {
        val list = arrayListOf(
            arrayListOf(1.0, 2.0, 3.0),
            arrayListOf(4.0, 5.0, 6.0),
            arrayListOf(7.0, 8.0, 9.0),
        )

        val covarianceMatrix = list.toCovarianceMatrix()
        covarianceMatrix.forEach { row ->
            println(row)
        }
    }

    @Test
    fun test2_getCovarianceMatrix() {
        val list = arrayListOf(
            arrayListOf(3.0, 1.0, 8.0),
            arrayListOf(2.0, 6.0, 7.0),
            arrayListOf(4.0, 9.0, 5.0),
            arrayListOf(5.0, 4.0, 2.0),
        )

        val covarianceMatrix = list.toCovarianceMatrix()
        covarianceMatrix.forEach { row ->
            println(row)
        }
    }
}